package com.wc.AlgoOJ._区间DP.合并石子;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/10/2 17:04
 * @description http://43.138.190.70:8888/p/LQ1454
 */

public class Main {
    /**
     * 思路：
     * 典型的区间DP板子
     * 加强
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 310, INF = 0x3f3f3f3f;
    // f[i][j][k] 表示从 i 到 j 颜色为 k 的最小时间
    static int[][][] f = new int[N][N][3];
    static int[][] num = new int[N][N];
    static int[][] cost = new int[N][N];
    static int[] sum = new int[N];
    static int[] w = new int[N];
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) w[i] = sc.nextInt();
        for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + w[i];
        for (int i = 1; i <= n; i++) {
            for (int j = i; j <= n; j++) {
                num[i][j] = j - i + 1;
                for (int k = 0; k < 3; k++) {
                    f[i][j][k] = INF;
                }
            }
        }
        for (int i = 1; i <= n; i++) {
            int color = sc.nextInt();
            f[i][i][color] = 0;
        }

        for (int len = 2; len <= n; len++) {
            for (int l = 1; l + len - 1 <= n; l++) {
                int r = l + len - 1;
                for (int c = 0; c < 3; c++) {
                    int minv = INF;
                    for (int md = l; md + 1 <= r; md++) {
                        if (f[l][md][c] != INF && f[md + 1][r][c] != INF) {
                            minv = Math.min(minv, f[l][md][c] + f[md + 1][r][c] + sum[r] - sum[l - 1]);
                        }
                    }
                    if (minv == INF) continue;
                    f[l][r][(c + 1) % 3] = Math.min(f[l][r][(c + 1) % 3], minv);
                    num[l][r] = 1;
                    cost[l][r] = Math.min(f[l][r][0], Math.min(f[l][r][1], f[l][r][2]));
                }
            }
        }
        for (int l = 1; l <= n; l++) {
            for (int r = l; r <= n; r++) {
                for (int md = l; md <= r; md++) {
                    if (num[l][r] > num[l][md] + num[md + 1][r]) {
                        num[l][r] = num[l][md] + num[md + 1][r];
                        cost[l][r] = cost[l][md] + cost[md + 1][r];
                    } else if (num[l][r] == num[l][md] + num[md + 1][r]) {
                        cost[l][r] = Math.min(cost[l][r], cost[l][md] + cost[md + 1][r]);
                    }
                }
            }
        }
//        for (int md = 1; md <= n; md++) {
//            for (int l = 1; l <= md; l++) {
//                for (int r = md + 1; r <= n; r++) {
//                    if (num[l][r] > num[l][md] + num[md + 1][r]) {
//                        num[l][r] = num[l][md] + num[md + 1][r];
//                        cost[l][r] = cost[l][md] + cost[md + 1][r];
//                    } else if (num[l][r] == num[l][md] + num[md + 1][r]) {
//                        cost[l][r] = Math.min(cost[l][r], cost[l][md] + cost[md + 1][r]);
//                    }
//                }
//            }
//        }
        out.printf("%d %d\n", num[1][n], cost[1][n]);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
